import { Component, OnInit } from '@angular/core'
import { ActivatedRoute } from '@angular/router'

import { ERoleType } from '@shared/enums'
import { DataService } from '@shared/services/data.service'
import { IAamsLevel } from '@shared/components/aams-select/aams-select.interface'

@Component({
  selector: 'app-merchant-detail-tab-user',
  templateUrl: './tab-user.component.html',
  styleUrls: ['../../../../shared/styles/table.less'],
})
export class MerchantDetailTabUserComponent implements OnInit {
  params: {[code: string]: string}
  merchantRole = ERoleType.Merchant
  insCode: string

  constructor(
    public route: ActivatedRoute,
    private dataService: DataService,
  ) {}

  ngOnInit(): void {
    this.initQueryParams()
    this.initialData()
  }

  initQueryParams(): void {
    this.route.parent.params.subscribe(params => {
      const intMerCode = params['id']
      this.params = {
        intMerCode,
        userType: IAamsLevel.Merchant
      }
    })
  }

  initialData() {
    this.dataService.merchant$.value$.subscribe(merchant => {
      if (Object.keys(merchant).length <= 0) return
      this.insCode = merchant.common.insCode
    })
  }
}
